home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / IRC client Source / ircle sources / IRCNotify.p < prev    next >
Encoding:
Text File  |  1993-06-05  |  4.1 KB  |  199 lines  |  [TEXT/PJMM]

  1. {    ircle - Internet Relay Chat client    }
  2. {    File: IRCNotify    }
  3. {    Copyright © 1992 Olaf Titz (s_titz@ira.uka.de)    }
  4.  
  5. {    This program is free software; you can redistribute it and/or modify    }
  6. {    it under the terms of the GNU General Public License as published by    }
  7. {    the Free Software Foundation; either version 2 of the License, or    }
  8. {    (at your option) any later version.    }
  9.  
  10. {    This program is distributed in the hope that it will be useful,    }
  11. {    but WITHOUT ANY WARRANTY; without even the implied warranty of    }
  12. {    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    }
  13. {    GNU General Public License for more details.    }
  14.  
  15. {    You should have received a copy of the GNU General Public License    }
  16. {    along with this program; if not, write to the Free Software    }
  17. {    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    }
  18.  
  19. unit IRCNotify;
  20. { Deals with the /notify command }
  21.  
  22. interface
  23.  
  24. uses
  25.     TCPTypes, TCPStuff, TCPConnections,{}
  26.     Coroutines, ApplBase, MsgWindows, InputLine, {}
  27.     IRCGlobals, IRCaux, IRCPreferences, IRCChannels;
  28.  
  29. procedure InitIRCNotify;
  30. { Startup }
  31.  
  32. procedure DoNotify (var s: string);
  33. { Processes the NOTIFY command }
  34.  
  35. procedure IsonReply (var s: string);
  36. { Processes ISON replies from server }
  37.  
  38. procedure OneNotify (var s: string; ison: boolean);
  39. { Processes explicit signon/off messages }
  40.  
  41. procedure RunNotify;
  42. { Does periodic queries }
  43.  
  44. implementation
  45.  
  46. var
  47.     doit, pending: boolean;
  48.     themap: set of byte;
  49.     noti: Handle;
  50.  
  51. procedure InitIRCNotify;
  52.     begin
  53.         doit := false;
  54.         pending := false;
  55.         themap := [];
  56.         noti := NewHandle(0);
  57.     end;
  58.  
  59. procedure RunNotify0;
  60.     var
  61.         s: string;
  62.         n: integer;
  63.     begin
  64.         if serverStatus = 0 then begin
  65.             n := GetHandleSize(noti);
  66.             BlockMove(noti^, @s[1], n);
  67.             s[0] := chr(n);
  68.             insert('ISON ', s, 1);
  69.             PutLine(s);
  70.         end;
  71.     end;
  72.  
  73.  
  74.  
  75. procedure DoNotify (var s: string);
  76.     var
  77.         i, n: integer;
  78.         j: byte;
  79.         olddoit: boolean;
  80.         p: string;
  81.     begin
  82.         if s[0] = chr(0) then begin
  83.             pending := false;
  84.             RunNotify0;
  85.         end;
  86.         while s[0] <> chr(0) do begin
  87.             NextArg(s, p);
  88.             insert(' ', p, 255);
  89.             if p[1] = '-' then begin
  90.                 n := length(p) - 1;
  91.                 i := Munger(noti, 0, @p[2], n, Ptr(1), 0);
  92.                 if i > 0 then begin
  93.                     for j := i to 255 - n do
  94.                         if j + n in themap then
  95.                             themap := themap + [j]
  96.                         else
  97.                             themap := themap - [j];
  98.                     for j := 255 - n + 1 to 255 do
  99.                         themap := themap - [j];
  100.                 end
  101.             end
  102.             else begin
  103.                 if length(p) + GetHandleSize(noti) < 250 then
  104.                     i := PtrAndHand(@p[1], noti, length(p));
  105.             end;
  106.         end;
  107.         pending := false;
  108.         i := GetHandleSize(noti);
  109.         olddoit := doit;
  110.         doit := (i > 0);
  111.         if doit then begin
  112.             BlockMove(noti^, @s[1], i);
  113.             s[0] := chr(i);
  114.             insert('*** Notify List: ', s, 1);
  115.             LineMsg(s);
  116.             if not olddoit then
  117.                 RunNotify;
  118.         end;
  119.     end;
  120.  
  121.  
  122. procedure onestring (i: integer; var s: string);
  123.     var
  124.         n: integer;
  125.         no: CharsHandle;
  126.     begin
  127.         n := GetHandleSize(noti);
  128.         if i > n then
  129.             s := ''
  130.         else begin
  131.             no := CharsHandle(noti);
  132.             BlockMove(@no^^[i], @s[1], n - i + 1);
  133.             s[0] := chr(n - i + 1);
  134.             i := pos(' ', s);
  135.             if i > 0 then
  136.                 s[0] := chr(i - 1);
  137.         end;
  138.     end;
  139.  
  140.  
  141. procedure OneNotify (var s: string; ison: boolean);
  142.     var
  143.         i: integer;
  144.     begin
  145.         i := Munger(noti, 0, @s[1], length(s), nil, 0);
  146.         if i >= 0 then begin
  147.             if ison then
  148.                 themap := themap + [i]
  149.             else
  150.                 themap := themap - [i];
  151.         end;
  152.     end;
  153.  
  154.  
  155. procedure IsonReply (var s: string);
  156.     var
  157.         p: string;
  158.         i: integer;
  159.         j: byte;
  160.         newmap: set of byte;
  161.     begin
  162.         if pending then begin
  163.             newmap := [];
  164.             while s[0] > chr(0) do begin
  165.                 NextArg(s, p);
  166.                 i := Munger(noti, 0, @p[1], length(p), nil, 0);
  167.                 if i >= 0 then
  168.                     newmap := newmap + [i];
  169.             end;
  170.             for j := 0 to 255 do
  171.                 if (j in themap) and (not (j in newmap)) then begin
  172.                     onestring(j, p);
  173.                     insert('*** Signoff: ', p, 1);
  174.                     Message(p);
  175.                 end
  176.                 else if (not (j in themap)) and (j in newmap) then begin
  177.                     onestring(j, p);
  178.                     insert('*** Signon: ', p, 1);
  179.                     Message(p);
  180.                 end;
  181.             themap := newmap;
  182.             pending := false
  183.         end
  184.         else begin
  185.             insert('*** Signed on: ', s, 1);
  186.             LineMsg(s)
  187.         end
  188.     end;
  189.  
  190.  
  191. procedure RunNotify; { Does periodic queries }
  192.     begin
  193.         if doit and (not pending) then begin
  194.             pending := true;
  195.             RunNotify0
  196.         end
  197.     end;
  198.  
  199. end.